//
//  LTBookExpandCell.m
//  LearnTeacher
//
//  Created by yang bo on 2024/4/13.
//

#import "LTBookExpandCell.h"
#import "LTExpandItemCollectionCell.h"
@interface LTBookExpandCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSArray *dataList;
@end
@implementation LTBookExpandCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.layout.minimumLineSpacing = 24;
    self.layout.minimumInteritemSpacing = 0;
    self.layout.itemSize = CGSizeMake(floor((SCREEN_W - 32) / 4), 44);
    self.collectionView.contentInset = UIEdgeInsetsMake(20, 0, 20, 0);
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([LTExpandItemCollectionCell class]) bundle:nil] forCellWithReuseIdentifier:@"ID"];
    self.dataList = @[
        @{@"icon": @"ic_listen_speak", @"name": @"听说", @"type": @1},
        @{@"icon": @"ic_listen", @"name": @"听力", @"type": @2},
        @{@"icon": @"ic_gendu", @"name": @"跟读", @"type": @3},
        @{@"icon": @"ic_exam", @"name": @"笔试", @"type": @4},
        @{@"icon": @"ic_yinbiao", @"name": @"音标", @"type": @5},
        @{@"icon": @"ic_model", @"name": @"典范", @"type": @6},
        @{@"icon": @"ic_new_concept", @"name": @"新概念", @"type": @7},
        @{@"icon": @"ic_black", @"name": @"黑布林", @"type": @8},
//        @{@"icon": @"ic_interset", @"name": @"趣味", @"type": @9},
//        @{@"icon": @"ic_see_see", @"name": @"看一看", @"type": @10}
    ];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataList.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LTExpandItemCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ID" forIndexPath:indexPath];
    NSDictionary *dic = self.dataList[indexPath.item];
    cell.iconImageV.image = [UIImage imageNamed:dic[@"icon"]];
    cell.nameLab.text = dic[@"name"];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.dataList[indexPath.item];
    if(self.itemTapBlock) {
        self.itemTapBlock([dic[@"type"] integerValue], dic[@"name"]);
    }
}

@end
